In a social network, one user has many friends. Each friend of the user also has many friends. A friend of a friend may be a person that the user knows or expects to know. If the friend of the friend can be recommended to the user, it is conducive to establish a more perfect friend relationship for the user. Conventional friend relationship query services all provide services for querying for a direct friend, that is, a first-degree friend. When the friend of the friend, that is, a second-degree friend, needs to be searched for, a second-degree friend relationship may be calculated offline and stored in advance. During a query, the second-degree friend may be directly obtained from a pre-storage location. In this manner, however, the second-degree friend relationship often cannot be updated in time. In addition, storage of the second-degree friend relationship that is calculated offline may consume a large amount of machine resources.